<?php
/**
 * Project ad-manager-backend
 * Author: Gardennet
 * Date: 2018/8/1
 * Time: 17:18
 */

namespace App\Helpers;


class ScopeHelper
{
    /**
     * 根据类型获取所有作用域
     *
     * @param string $type user seller admin
     * @return string
     */
    public static function getAllScopeByType($type = 'user')
    {
        $config = config('scope');
        $scope = [];
        foreach ($config as $k=>$v){
            if(stripos($k,$type.'_') !== false){
                $scope[] = $k;
            }
        }

        return implode(',',$scope);
    }

    /**
     * 获取后台作用域
     *
     * admin_base
     * admin_super  超管
     * admin_operation_director 运营总监
     * admin_operation_specialist   运营专员
     * admin_fiance 财务
     * admin_customer_service_manager   客服经理
     * admin_customer_service_specialist    客服专员
     * admin_product_manager  产品经理
     *
     * @param string $type
     * super 超管 运营总监 运营专员 财务 客服经理 客服专员 产品经理
     * level1 超管
     * level2 超管 财务
     * level3 超管 运营总监
     * level4 超管 运营总监 运营专员
     * level5 超管 运营总监 运营专员 产品经理
     * level6 超管 运营总监 运营专员 客服经理 客服专员
     * @return string
     */
    public static function getAdminScope($type = 'super')
    {
        switch ($type){
            case 'level1':
                $scope = 'admin_super';
                break;
            case 'level2':
                $scope = 'admin_super,admin_fiance';
                break;
            case 'level3':
                $scope = 'admin_super,admin_operation_director';
                break;
            case 'level4':
                $scope = 'admin_super,admin_operation_director,admin_operation_specialist';
                break;
            case 'level5':
                $scope = 'admin_super,admin_operation_director,admin_operation_specialist,admin_product_manager';
                break;
            case 'level6':
                $scope = 'admin_super,admin_operation_director,admin_operation_specialist,admin_customer_service_manager,admin_customer_service_specialist';
                break;
            case 'super':
            default:
                $scope = self::getAllScopeByType('admin');
                break;
        }
        return $scope;
    }
}